home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / java / twolists / quitdialog.java < prev    next >
Encoding:
Java Source  |  1997-02-06  |  1.7 KB  |  69 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class QuitDialog extends Dialog {
  8.     void yesButton_Clicked(Event event) {
  9.         getParent().handleEvent(new Event(this, Event.WINDOW_DESTROY, null));
  10.     }
  11.  
  12.     void noButton_Clicked(Event event) {
  13.         hide();
  14.     }
  15.  
  16.  
  17.     public QuitDialog(Frame parent, boolean modal) {
  18.  
  19.         super(parent, modal);
  20.  
  21.         //{{INIT_CONTROLS
  22.         setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
  23.         addNotify();
  24.         resize(insets().left + insets().right + 295,insets().top + insets().bottom + 92);
  25.         yesButton = new java.awt.Button("Yes");
  26.         yesButton.reshape(insets().left + 51,insets().top + 20,60,40);
  27.         add(yesButton);
  28.         noButton = new java.awt.Button("No");
  29.         noButton.reshape(insets().left + 165,insets().top + 20,60,40);
  30.         add(noButton);
  31.         setResizable(false);
  32.         //}}
  33.     }
  34.  
  35.     public QuitDialog(Frame parent, String title, boolean modal) {
  36.         this(parent, modal);
  37.         setTitle(title);
  38.     }
  39.  
  40.     public synchronized void show() {
  41.         Rectangle bounds = getParent().bounds();
  42.         Rectangle abounds = bounds();
  43.  
  44.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  45.              bounds.y + (bounds.height - abounds.height)/2);
  46.  
  47.         super.show();
  48.     }
  49.  
  50.     public boolean handleEvent(Event event) {
  51.         if(event.id == Event.WINDOW_DESTROY) {
  52.             hide();
  53.             return true;
  54.         }
  55.         if (event.target == noButton && event.id == Event.ACTION_EVENT) {
  56.             noButton_Clicked(event);
  57.         }
  58.         if (event.target == yesButton && event.id == Event.ACTION_EVENT) {
  59.             yesButton_Clicked(event);
  60.         }
  61.         return super.handleEvent(event);
  62.     }
  63.  
  64.     //{{DECLARE_CONTROLS
  65.     java.awt.Button yesButton;
  66.     java.awt.Button noButton;
  67.     //}}
  68. }
  69.